<template>
  <div>
    <div class="flexCss">
      <div class="integralCss">
        <div>积分余额</div>
        <div>{{integral_balance}}</div>
      </div>
      <div class="integralCss">
        <div>累计使用</div>
        <div>{{use_integral}}</div>
      </div>
    </div>
    <!-- 记录 -->
    <div class="tabRecord">
       <el-tabs tab-position="top" style=";" @tab-click="tabclick">
          <el-tab-pane label="全部记录">
              <integralRecord ref="integralRecord"></integralRecord>
          </el-tab-pane>
          <el-tab-pane label="获得记录">
              <integralRecord ref="integralRecord" @onChange='onChildValue'></integralRecord>
          </el-tab-pane>
          <el-tab-pane label="使用记录">
              <integralRecord ref="integralRecord"></integralRecord>
          </el-tab-pane>
        </el-tabs>
    </div>
  </div>
</template>

<script>
  import integralRecord from "./integralRecord.vue"
  export default {
    data() {
      return {
        loading: false,
        keyword: "",
        userId: "",
        integral_balance:"",
        use_integral:"",
        formdata: [],
        totalusers: 0, //总行数
        pageSize: 10, //每页几行
        startpage: 1, //起始页
      }
    },
    components:{
      integralRecord
    },
    created() {
      this.userId = this.$route.query.userId;
      window.localStorage.setItem("userId",this.userId)
    },
    mounted() {
      // this.getIntegralRecordList()
    },
    methods: {
      //子向父传值绑定的方法，接收子传过来的值
       onChildValue(val){
          this.integral_balance = val.integral_balance
          this.use_integral = val.use_integral
      },
      //切换获取积分记录
      tabclick(e){
          if(e.index==0){
            this.$refs.integralRecord.getIntegralRecordList();
          } else if(e.index==1){
            this.$refs.integralRecord.getIntegralRecordList("add")
          } else if(e.index==2){
            this.$refs.integralRecord.getIntegralRecordList("use")
          }
      },
      //获取分页列表
      getIntegralRecordList() {
        let params = {
          "page": this.startpage,
          "limit": this.pageSize,
          "user_id": this.userId
        }
        //调用后台提供的接口方法
        this.$api.getIntegralRecordList(params).then(res => {
          if (res.data.level == "success") {
            this.integral_balance = res.data.integral_balance
            this.use_integral = res.data.use_integral
            this.formdata = res.data.data
            this.totalusers = res.data.page_info.total
            this.loading = false
          } else {
            this.$message.error(res.data.message)
          }


        })
      },
      //分页 pageChange当前页发生改变触发函数
      async pageChange(page) {
        this.startpage = page
        this.loading = true
        //调用获取列表的方法
        this.getIntegralRecordList()
      },
    }
  }
</script>
<style scoped="scoped">
  .integralCss {
    background-color: #81c0f5;
    color: #fff;
    width: 20%;
    min-width: 160px;
    margin-left: 10px;
    text-align: center;
    border-radius: 12px;
    height: 80px;
    line-height: 25px;
    padding: 15px;
    font-size: 18px;
  }

  .flexCss {
    display: flex;
    justify-content: space-evenly;
    margin-bottom: 15px;
  }
  .tabRecord{
    padding: 10px 30px 0px;
  }
</style>
